<!doctype html>
<html lang="en-US">
  <head>
    <link href="/assets/index.css" rel="stylesheet" type="text/css" />
    <script crossorigin="anonymous" src="/test-harness.js"></script>
    <script crossorigin="anonymous" src="/test-page-object.js"></script>
    <script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
  </head>
  <body>
    <main id="webchat"></main>
    <script>
      run(async function () {
        const adaptiveCard = {
          content: {
            type: 'AdaptiveCard',
            $schema: 'http://adaptivecards.io/schemas/adaptive-card.json',
            version: '1.5',
            body: [
              {
                type: 'Input.Text',
                id: 'name',
                label: 'What is your full name',
                placeholder: 'For example, John Doe',
                inlineAction: {
                  type: 'Action.Submit',
                  title: 'Submit'
                }
              }
            ]
          },
          contentType: 'application/vnd.microsoft.card.adaptive'
        };
        const { directLine, store } = testHelpers.createDirectLineEmulator();

        WebChat.renderWebChat({ directLine, store }, document.getElementById('webchat'));

        await pageConditions.uiConnected();

        await directLine.emulateIncomingActivity({
          attachments: [adaptiveCard],
          id: 'a-00001',
          text: 'Hello, World!',
          type: 'message'
        });

        await pageConditions.numActivitiesShown(1);

        expect(pageElements.activityContents()[0]).toHaveProperty('textContent', 'Hello, World!');

        const textInput1 = document.querySelector('.ac-textInput');

        await host.click(textInput1);
        await host.sendKeys('John Doe');

        // Modifying "adaptiveCardsHostConfig" props will cause the Adaptive Card to be re-rendered.
        WebChat.renderWebChat({ adaptiveCardsHostConfig: {}, directLine, store }, document.getElementById('webchat'));

        await directLine.emulateIncomingActivity({
          attachments: [adaptiveCard],
          id: 'a-00001',
          text: 'Aloha!',
          type: 'message'
        });

        expect(pageElements.activityContents()[0]).toHaveProperty('textContent', 'Aloha!');

        const textInput2 = document.querySelector('.ac-textInput');

        expect(textInput2).toHaveProperty('value', 'John Doe');
      });
    </script>
  </body>
</html>
